/* eslint-disable import/no-dynamic-require */
/* eslint-disable no-console */
const path = require('path');
const chalk = require('chalk');
const express = require('express');
const historyFallback = require('connect-history-api-fallback');
const getPort = require('get-port');

const start = async () => {
  const app = express();

  const port = await getPort({ port: process.env.PORT || getPort.makeRange(3000, 3100) });

  const server = app.listen(port, 'localhost', () => {
    const address = server.address().address;
    const url = `http://${address}:${port}/`;

    app.use(historyFallback());

    app.use('/', express.static(path.join(__dirname, '../build')));

    console.log([
      chalk.bgMagentaBright.black(' INFO: '),
      chalk.bgGreenBright.black(` serve server is now up at ${url} `),
    ].join(''));
  });
};

start();
